package com.alibaba.ai.dao;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import com.alibaba.ai.entity.YPost;

import java.util.List;

/**
 * 用户
 */

@Repository
public interface YPostMapper {


    //帖子排行-——按周
    @Select("select p.Y_POST_TITLE,p.Y_POST_CLICK_NUM from Y_POST p where p.Y_POST_PUBTIME=(select to_char(sysdate,'yyyy-MM-dd') from dual) order by p.Y_POST_CLICK_NUM DESC")
    List<YPost> getPostListByWeek();

    //帖子排行-——按月
    @Select("select p.Y_POST_TITLE,p.Y_POST_CLICK_NUM from Y_POST p where p.Y_POST_PUBTIME=(select to_char(sysdate,'yyyy-MM') from dual) order by p.Y_POST_CLICK_NUM DESC")
    List<YPost> getPostListByMonth();

    //个人信息页面————通过id查询 论坛 帖子 发布日期
    @Select("select p.y_post_title,f.y_for_name,p.y_post_pubtime from Y_POST p INNER JOIN Y_FORUM f on f.y_for_id = p.y_forum_id where p.y_users_id=#{yUsersId}")
    List<YPost> getPostListByUserId(@Param("yUsersId") Integer yUsersId);

    //模糊查询操作————精华帖和业主论坛两个页面的搜索模块
    @Select("select * from Y_POST where Y_POST_TITLE like CONCAT('%',#{yPostTitle},'%')")
    List<JSONObject> getPostlistByTitle(@Param("yPostTitle") String yPostTitle);



}
